package mvp.com.bbc.rcjavaretrofitdaggermvp.presenter;

import javax.inject.Inject;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.contact.ArtListContact;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.NetworkUtil;
import mvp.com.bbc.rcjavaretrofitdaggermvp.bean.CommunityListBean;
import mvp.com.bbc.rcjavaretrofitdaggermvp.model.ArtListModel;

/**
 * Created by ${cbf} on 2017/12/3.
 */

public class ArtListPresenter implements ArtListContact.ArtListPresenter {
    private ArtListContact.ArtListModel listModel;
    private ArtListContact.ArtListView listView;

    @Inject
    public ArtListPresenter(ArtListContact.ArtListView listViews) {
        this.listView = listViews;
        listModel = new ArtListModel();

    }

    @Override
    public void artListPresenter(String themeid, String currentPage, String userid) {
        listModel.artListModel(themeid, currentPage, userid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<CommunityListBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull CommunityListBean listBean) {
                        listView.artListView(listBean);
                        NetworkUtil.onSuccess();
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        NetworkUtil.onError();

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
